package group.hhsw.purchase.service.impl;

import group.hhsw.common.model.vo.DetailOrder;
import group.hhsw.common.model.params.Check;
import group.hhsw.feign.clients.ProductClient;
import group.hhsw.purchase.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("4")
public class ReduceAllowanceService implements PurchaseService {

    @Autowired
    private ProductClient productClient;

    @Override
    public DetailOrder atomicService(Check check) {
        DetailOrder detailOrder = new DetailOrder();
        Integer integer = productClient.lockInventory(check.getProductId());
        //如果库存减少接口返回值不为1则证明商品库存不足
        detailOrder.setProductAllowanceReduceIsOk((integer == 1));
        return detailOrder;
    }
}
